home *** CD-ROM | disk | FTP | other *** search
- /* FILENAME: piano.c
-
- */
-
- #include <stdio.h> /* use unbuffered i/o */
- #include <ctype.h>
-
- #define C 262 /* define frequencies */
- #define D 294
- #define E 330
- #define F 349
- #define G 392
- #define A 440
- #define B 494
- #define C2 524
-
- main ()
- {
- int key, freq, tempo, time;
-
- puts ("Please enter the basic tempo: 10 = 1 second.");
- scanf ("%d", &tempo);
- printf ("%d\n\r", tempo); /* echo input */
- puts ("Thank you. Use the key row a-k to play notes. The\n\r");
- puts ("shift key doubles the duration. A ! halts the show.");
-
- while ( (key = getchar()) != '!')
- {
- time = isupper (key) ? 2 * tempo : tempo;
- key = tolower (key);
- switch (key)
- {
- case 'a': tone ( C, time);
- break;
- case 's': tone ( D, time);
- break;
- case 'd': tone ( E, time);
- break;
- case 'f': tone ( F, time);
- break;
- case 'g': tone ( G, time);
- break;
- case 'h': tone ( A, time);
- break;
- case 'j': tone ( B, time);
- break;
- case 'k': tone ( C2, time);
- break;
- default: break;
- }
- }
- puts ("Bye bye!\n\r");
- }
-